local skel = fk.CreateSkill {
  name = "lb__wugui",
  tags = { Skill.Wake }
}

Fk:loadTranslationTable {
  ["lb__wugui"] = "无归",
  --[":lb__wugui"] = "<b>觉醒技</b>，当弃牌堆中有至少六张武器牌时，你加1点体力上限并回复1点体力，本局游戏你的每个回合结束时，若本回合你未造成过伤害，你失去1点体力。",
  --9.23
  [":lb__wugui"] = "<b>觉醒技</b>，当弃牌堆中有至少六张武器牌时，你加1点体力上限并回复1点体力，本局游戏你的每个回合结束时，若你因<a href=':lb__xunshu'><font color='red'>〖寻赎〗</font></a>获得的牌不为<font color=#CC3131><b>♥</b></font>，你失去1点体力。",


  ["@lb__wugui"] = "无归",

  ["$lb__wugui1"] = "而后寻索，而后顿悟，而后存在…",
  ["$lb__wugui2"] = "无妨，就在此了结。",
}


skel:addEffect(fk.AfterCardsMove, {
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(skel.name) and player:usedSkillTimes(skel.name, Player.HistoryGame) == 0 then
      local num = 0
      for _, id in ipairs(player.room.discard_pile) do
        if Fk:getCardById(id).sub_type == Card.SubtypeWeapon then
          num = num + 1
          if num > 5 then
            return true
          end
        end
      end
    end
  end,
  can_wake = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player, 1)
    if player.dead then return false end
    room:recover {
      who = player,
      num = 1,
      skillName = skel.name,
      recoverBy = player,
    }
    if player.dead then return false end
    room:setPlayerMark(player, "@lb__wugui", 0)
    room:setPlayerMark(player, "lb__wugui", 1)
  end,
  can_refresh = function(self, event, target, player, data)
    if player:hasSkill(skel.name, true) and player:usedSkillTimes(skel.name, Player.HistoryGame) == 0 then
      for _, move in ipairs(data) do
        if move.toArea == Card.DiscardPile then
          return true
        end
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.DiscardPile then
            return true
          end
        end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    skel:onAcquire(player, false)
  end,
})

skel:addEffect(fk.TurnEnd, {
  is_delay_effect = true,
  anim_type = "negative",
  can_trigger = function(self, event, target, player, data)
    --[[
    return target == player and player:hasSkill(skel.name) and player:getMark(skel.name) > 0
        and #player.room.logic:getEventsOfScope(GameEvent.Damage, 1, function(e)
          local damage = e.data
          return damage.from and damage.from == player and not damage.prevented
        end, Player.HistoryTurn) == 0
    --]]
    return target == player and player:hasSkill(skel.name) and player:getMark(skel.name) > 0
        and player:getMark("lb__xunshu-turn") > 0
  end,
  on_use = function(self, event, target, player, data)
    player.room:loseHp(player, 1, skel.name)
  end,
})

skel:addAcquireEffect(function(self, player, is_start)
  local room = player.room
  local num = 0
  for _, id in ipairs(room.discard_pile) do
    if Fk:getCardById(id).sub_type == Card.SubtypeWeapon then
      num = num + 1
    end
  end
  room:setPlayerMark(player, "@lb__wugui", num)
end)

skel:addLoseEffect(function(self, player, is_death)
  player.room:setPlayerMark(player, "@lb__wugui", 0)
  player.room:setPlayerMark(player, "lb__wugui", 0)
end)

return skel
